﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" 
    CodeBehind="configs.aspx.cs" Inherits="VQWEB.administrator.configs.configs" %>

<asp:Content ID="Content2" ContentPlaceHolderID="Content_backend" runat="server">
<div class="alert alert-danger hidden" id="hander_error"></div>
    <form id="frm_configs" method="post">
    <ul class="nav nav-tabs" id="ConfigsTab" style="margin-bottom: 0px">
        <li class="active"><a href="#general" data-toggle="tab">General</a></li>
        <li><a href="#webmail" data-toggle="tab">Web Mail</a></li>
        <li><a href="#settings" data-toggle="tab">Settings</a></li>        
        <li><a href="#google-facebook" data-toggle="tab">Google & Facebook</a></li>
        <li><a href="#closeweb" data-toggle="tab">Close Website</a></li>
    </ul>
    <div class="tab-content" style="border-left: 1px solid #DDDDDD; border-right: 1px solid #DDDDDD;
        border-bottom: 1px solid #DDDDDD; padding: 15px">
        <div class="tab-pane active" id="general">
            <div class="form-group">
                <label>
                    Tieu de Website
                </label>
                <input type="text" class="form-control" name="title_web" />
            </div>
            <div class="form-group">
                <label>
                    Meta Keyword
                </label>
                <textarea class="form-control" name="meta_keyword" cols="3" rows="2"></textarea>
                <div id="view">
                </div>
            </div>
            <div class="form-group">
                <label>
                    Meta Description
                </label>
                <textarea class="form-control" name="meta_description" cols="3" rows="2"></textarea>
            </div>
            <div class="form-group">
                <label>
                    Thong tin doanh nghiep
                </label>
                <textarea class="form-control" name="info_company" cols="3" rows="4"></textarea>
            </div>
        </div>
        <div class="tab-pane" id="webmail">
            <div class="form-group">
                <label>
                    SMTP Server (Smtp Gmail: smtp.gmail.com)
                </label>
                <input type="text" class="form-control" name="webmail_smtpserver" />
            </div>
            <div class="form-group">
                <label>
                    SMTP Port (Port Gmail: 587)
                </label>
                <input type="text" class="form-control" name="webmail_smtport" />
            </div>
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="webmail_enablessl" value="True" />
                    Webmail EnableSsl (neu Host yeu cau checked = true)
                </label>
            </div>
            <div class="form-group">
                <label>
                    Webmail UserName
                </label>
                <input type="text" class="form-control" name="webmail_username" />
            </div>
            <div class="form-group">
                <label>
                    Webmail Password
                </label>
                <input type="password" class="form-control" name="webmail_password" />
            </div>
        </div>
        <div class="tab-pane" id="settings">
            <div class="form-group">
                <label>
                    Support Online
                </label>
                <textarea class="form-control" name="support_online" cols="3" rows="2"></textarea>
            </div>
            
        </div>       
        <div class="tab-pane" id="google-facebook">
            <div class="form-group">
                <label>
                    Embed Google
                </label>
                <textarea class="form-control" name="embed_google" cols="3" rows="2"></textarea>
            </div>
            <div class="form-group">
                <label>
                    Embed Facebook
                </label>
                <textarea class="form-control" name="embed_facebook" cols="3" rows="2"></textarea>
            </div>
        </div>
         <div class="tab-pane" id="closeweb">
            <div class="form-group">
                <label>
                    Ly do close website
                </label>
                <textarea class="form-control" name="close_reason" cols="3" rows="2"></textarea>
            </div>
            <div class="checkbox">
                <label>
                    <input name="close_website" type="checkbox" value="True" />
                    Close website
                </label>
            </div>
        </div>
    </div>
    </form>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/configs/handler";
        $("#ConfigsTab a").click(function (e) {
            e.preventDefault()
            $(this).tab("show")
        })

        $(document).ready(function () {
            $.get(url_ashx, { show_configs: "show_configs" }, function (data) {
                var plusData = $.parseJSON(data);
                ShowConfigsHtml(plusData);
            });
        });

        $("#btnSave").live("click", function () {
            var arr = $("#frm_configs").serializeObject();
            $.post(url_ashx, { update_configs: window.escape(arr) }, function (data) {
                var plusData = $.parseJSON(data);
                ShowConfigsHtml(plusData);
                alert("Cập nhật thành công!");
            }).fail(function (jqXHR, textStatus, errorThrown) {
                $("#hander_error").removeClass("hidden").html("Co loi xay ra");
                alert("Have a Error:\n" + jqXHR.status + ": " + jqXHR.statusText);
            });
        });

      
        function ShowConfigsHtml(table) {
            var child = $("div.tab-content").find('*');
            $.each(table, function (i, obj) {              
                $.each(child, function () {
                    if ($(this).attr("name") != undefined) {
                        if ($(this).attr("name") == obj.config_key) {
                            if ($(this).is("input[type='checkbox']")) {
                                if (obj.config_value == "True")
                                    $(this).prop("checked", true);
                            }
                            else
                                $(this).attr("value", obj.config_value);
                        }
                    }
                });
            });
        }

    </script>
</asp:Content>
